/****************************************************************************
 * getcurtime.c
 * 1999 12 13
 * lee j.t.
 *
 * input  :
 * output :
 ****************************************************************************/
#include<stdio.h>
#include<string.h>
#include<sys/time.h>

#include<time.h>
#include<sys/times.h>

int getCurTime(char *cur_time)
{
    time_t  st_cal;
    struct  tm  *tmptr;

 struct  timeval  tp;
    struct  timezone  ticx;

 time(&st_cal);
    tmptr = localtime(&st_cal);

    strftime( cur_time, 23, "<%Y-%m-%d %H:%M:%S>", tmptr);
	/*
    gettimeofday(&tp,&ticx);
    sprintf(cur_time + 20 , "%02d", tp.tv_usec / 10000);
	*/

/*
printf( ">%ld %ld\n", tp.tv_sec, tp.tv_usec );
*/
    return;

}

int getCurTimeTic(long *daytic, long *clktic)
{
    time_t  st_cal;
    struct  tm  *tmptr;

    struct  timeval  tp;
    struct  timezone  ticx;

    clock_t      click_tic;
    struct  tms  time_tms;

    time(&st_cal);
    tmptr = localtime(&st_cal);

    click_tic = times(&time_tms) ? times(&time_tms) : 99;

    gettimeofday(&tp,&ticx);
#if 0
    {
        char cur_time[20];
        strftime( cur_time, 23, "%Y-%m-%d %H:%M:%S.", tmptr);
printf(">%s %d %ld %ld tic : %ld<\n",
cur_time,
tp.tv_usec/10000,
tp.tv_sec,
tp.tv_usec,
click_tic);
    }
#endif
    *daytic = tp.tv_sec;
    *clktic = click_tic;
    return;

}

#if 0
main()
{
        char ab[23];
        long a,b;
        getCurTime( ab);
        printf(">%s<(%d)\n", ab, strlen(ab));
}
#endif
#if 0
main(int argc, char *argv[])
{
    long    time_d1;
    long    time_t1;
    long    time_d2;
    long    time_t2;
    getCurTimeTic( &time_d1, &time_t1);
sleep(1);
    getCurTimeTic( &time_d2, &time_t2);
    {
        FILE * stderr_fp;
        if ((stderr_fp = fopen("stderr","a+")) == NULL)
        {
            fprintf(stderr, "log file open error\n");
        }
        fprintf(stderr_fp, "@%s %d %ld %07ld %ld %07ld\n", argv[0], getpid(),
        time_d1, time_t1,
        time_d2, time_t2);
    }
}
#endif
